import config from "config";
import httpFetch from "share/httpFetch";
import errorMessage from "share/errorMessage";

export default {
  // 查询配置项
  getConfigurationList(query) {
    return new Promise(function (resolve, reject) {
      httpFetch
        .post(`${config.baseUrl}/config/api/config/item`, query)
        .then(function (res) {
          resolve(res);
        })
        .catch(function (err) {
          errorMessage(err.response);
          reject(err.response);
        });
    });
  },
  // 添加规则
  addRule(configurationRule) {
    return new Promise(function (resolve, reject) {
      httpFetch
        .post(`${config.baseUrl}/config/api/config/rule`, configurationRule)
        .then(function (res) {
          resolve(res);
        })
        .catch(function (err) {
          errorMessage(err.response);
          reject(err.response);
        });
    });
  },
  // 删除规则
  deleteRule(id) {
    return new Promise(function (resolve, reject) {
      httpFetch
        .delete(`${config.baseUrl}/config/api/config/rule/${id}`)
        .then(function (res) {
          resolve(res);
        })
        .catch(function (err) {
          errorMessage(err.response);
          reject(err.response);
        });
    });
  },
  // 修改规则
  updateRule(configurationRule) {
    return new Promise(function (resolve, reject) {
      httpFetch
        .put(`${config.baseUrl}/config/api/config/rule`, configurationRule)
        .then(function (res) {
          resolve(res);
        })
        .catch(function (err) {
          errorMessage(err.response);
          reject(err.response);
        });
    });
  },
};
